package com.wfh.aihelper.ai;


import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.SystemMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Title: AiCodeHelper
 * @Author wangfenghuan
 * @Package com.wfh.aihelper.ai
 * @Date 2025/7/9 19:57
 * @description: ai编程助手
 */
@Service
@Slf4j
public class AiCodeHelper {

    @Resource
    private ChatModel qwenChatModel;

    private final String GREETING = "你是一名软件工程师";

    public String chat(String prompt) {
        SystemMessage systemMsg = SystemMessage.from(GREETING);
        UserMessage from = UserMessage.from(prompt);
        ChatResponse chat = qwenChatModel.chat(from, systemMsg);
        log.info("chat: {}", chat);
        return chat.aiMessage().text();
    }

    public String chatWith(UserMessage message) {
        ChatResponse chat = qwenChatModel.chat(message);
        AiMessage aiMessage = chat.aiMessage();
        log.info("chat: {}", aiMessage);
        return aiMessage.text();
    }
}
